#include <QWidget>
#include <QProgressBar>
#include <QStyleOptionViewItem>
#include "progressdelegate.h"

ProgressDelegate::ProgressDelegate(QObject *parent):
    QItemDelegate(parent)
{

}

ProgressDelegate::~ProgressDelegate()
{

}

QWidget *ProgressDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                      const QModelIndex &index) const
{
    QProgressBar *progress=new QProgressBar(parent);
    progress->setMinimum(0);
    progress->setMaximum(100);
    return progress;
}

void ProgressDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    int value = index.model()->data(index, Qt::EditRole).toInt();

    QProgressBar *progress = static_cast<QProgressBar*>(editor);
    progress->setValue(value);
}
void ProgressDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                  const QModelIndex &index) const
{
    QProgressBar *progress = static_cast<QProgressBar*>(editor);
    //progress->interpretText();
    int value = progress->value();

    model->setData(index, value, Qt::EditRole);
}

void ProgressDelegate::updateEditorGeometry(QWidget *editor,
        const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    editor->setGeometry(option.rect);
}
